package com.business.user.service.impl;


import java.util.Date;
import java.util.List;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.business.common.enums.ErrorEnum;
import com.business.common.exception.CustomException;
import com.business.user.mapper.MembershipPackageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.plugins.Page;
import com.business.common.utils.PageUtils;
import com.business.common.dto.R;

import com.business.user.entity.MemberOrder;
import com.business.user.mapper.MemberOrderMapper;
import com.business.user.service.MemberOrderService;



/**
 * 会员充值订单:业务接口实现类
 * @author chenjiehong
 * @date 2019-11-29 14:28:27
 * @since 1.0
 */
@Service
public class MemberOrderServiceImpl implements MemberOrderService {
    
    @Autowired
    private MemberOrderMapper memberOrderMapper;

    
    @Override
    @Transactional
    public MemberOrder add(MemberOrder memberOrder){
        if(memberOrder.getPackageId() == null){
            throw new CustomException(ErrorEnum.PARAMS_LOSE,"packageId");
        }
        if(memberOrder.getUserId() == null){
            throw new CustomException(ErrorEnum.PARAMS_LOSE,"userId");
        }
        memberOrder.setCreateTime(new Date());
        memberOrderMapper.insert(memberOrder);
        return memberOrder;
    }
    
    @Override
    public  MemberOrder query(Integer id){
        MemberOrder memberOrder = memberOrderMapper.selectById(id);
        return memberOrder;
    }
    
    @Override
    public PageUtils queryPage(Page<MemberOrder> page, MemberOrder memberOrder){
        Wrapper<MemberOrder> wrapper = new EntityWrapper<>(memberOrder);
        List<MemberOrder> result = memberOrderMapper.selectPage(page,wrapper);
        PageUtils pageUtils = new PageUtils(result, page.getTotal());
        return pageUtils;
    }
    

    
}